extension NumExtension on num {
  // 延迟
  Future<void> get seconds => Future.delayed(Duration(seconds: toInt()));
  Future<void> get milliseconds =>
      Future.delayed(Duration(milliseconds: toInt()));

  // 数值格式化
  String toStringWithDecimalPlaces(int decimalPlaces) {
    return toStringAsFixed(decimalPlaces).replaceAll(RegExp(r'\.?0*$'), '');
  }

  // 范围检查
  bool isBetween(num from, num to) {
    return from <= this && this <= to;
  }

  // 转换为带单位的字符串
  String toFileSize() {
    if (this < 1024) return '${toStringAsFixed(2)} B';
    if (this < 1024 * 1024) return '${(this / 1024).toStringAsFixed(2)} KB';
    if (this < 1024 * 1024 * 1024) {
      return '${(this / (1024 * 1024)).toStringAsFixed(2)} MB';
    }
    return '${(this / (1024 * 1024 * 1024)).toStringAsFixed(2)} GB';
  }
}
